package com.share.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.share.mapper.UserIdCardCurrentMapper;
import com.share.service.IUserIdCardCurrentService;
import com.share.user.admin.dtos.PayloadDTO;
import com.share.user.admin.pojos.UserIdCardCurrent;
import com.share.user.admin.vo.UserIdCardCurrentVo;
import com.share.util.common.PrivacyUtils;
import com.share.util.thread.ThreadLocalUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 当前有效身份证信息 服务实现类
 * </p>
 *
 * @author 胡先生
 * @since 2025-04-19
 */
@Service
public class UserIdCardCurrentServiceImpl extends ServiceImpl<UserIdCardCurrentMapper, UserIdCardCurrent> implements IUserIdCardCurrentService {


    @Override
    public UserIdCardCurrentVo getIdCard() {
        PayloadDTO payloadDTO = ThreadLocalUtils.get();
        QueryWrapper<UserIdCardCurrent> queryWrapperIdCard = new QueryWrapper<>();
        queryWrapperIdCard.eq("user_id",payloadDTO.getId());
        UserIdCardCurrent userIdCardCurrent = this.baseMapper.selectOne(queryWrapperIdCard);
        UserIdCardCurrentVo userIdCardCurrentVo = BeanUtil.copyProperties(userIdCardCurrent,UserIdCardCurrentVo.class);
        userIdCardCurrentVo.setIdNumber(PrivacyUtils.encryptIdCard(userIdCardCurrentVo.getIdNumber()));
        userIdCardCurrentVo.setName(PrivacyUtils.encryptName(userIdCardCurrentVo.getName()));
        return userIdCardCurrentVo;
    }
}
